# Maintainer EmanueL Czirai
# old Maintainer kfgz <kfgz at interia pl>
# Package based on xfce4-sensors-plugin
#also considered data from: https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/xfce4-sensors-plugin
#whose maintainers are:
# Maintainer: Evangelos Foutras <evangelos@foutrelis.com>
# Contributor: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Merk Matthias <macem@chello.at>

#get it ready for gdb debugging
DEBUG=0

pkgname=xfce4-sensors-plugin-git
pkgver=d943ea1
pkgrel=1
pkgdesc="A lm_sensors plugin for the Xfce panel"
arch=('i686' 'x86_64')
license=('GPL2')
#url="http://git.xfce.org/panel-plugins/xfce4-sensors-plugin/"
url="http://goodies.xfce.org/projects/panel-plugins/xfce4-sensors-plugin"
groups=('xfce4-goodies')
depends=('xfce4-panel>=4.6.0' 'lm_sensors>=3.1.0' 'libnotify>0.7.1' 'hicolor-icon-theme')
makedepends=('pkgconfig' 'intltool' 'xfce4-dev-tools' 'git' 'gnu-netcat' 'hddtemp>=0.3.beta15.45-2')
options=(!libtool)
optdepends=('hddtemp: for monitoring the temperature of hard drives')
conflicts=('xfce4-sensors-plugin' 'xfce4-sensors-plugin-svn')
provides=('xfce4-sensors-plugin')
install=xfce4-sensors-plugin.install

_gitroot="git://git.xfce.org/panel-plugins/xfce4-sensors-plugin"
_gitname="xfce4-sensors-plugin"

#patch1='010_fix_segfault_strcmp_sensorName.patch'
#patch2='020_fix_context_menu_did_not_appear.patch'
source=("${_gitname}::$_gitroot"
"$install"
#"$patch1"
#"$patch2"
)

sha512sums=('SKIP'
            'b487b27a22ae664027f07a4ee7640a696f2f18aa73163f80e7034396295b16da66221bee4e433d229fa98d7a846b19dc778abfa728a24a758a7ec80ba864e8bb')

#avoid this:
#acpi.c: In function ‘initialize_ACPI’:
#acpi.c:537:95: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
#                             ( g_strdup(_("ACPI")), 0, 0, g_strdup(_("ACPI")) );
#                                                                                               ^
#acpi.c:537:98: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
#                             ( g_strdup(_("ACPI")), 0, 0, g_strdup(_("ACPI")) );
#                                                                                                  ^
#cc1: all warnings being treated as errors
export CFLAGS="$CFLAGS -Wno-error=unused-value"
export CPPFLAGS="$CPPFLAGS -Wno-error=unused-value"
export CXXFLAGS="$CXXFLAGS -Wno-error=unused-value"

if [ -n "$DEBUG" ] && [ "$DEBUG" == "1" ]; then
  options+=(!strip)
fi
#debug mode for gdb, in case seg faults                                     
if [ -n "$DEBUG" ] && [ "$DEBUG" == "1" ]; then
  #XXX: the current state of these vars are written to files in the prepare() so if you change them, rerun prepare
  #when using -O0 , /usr/include/features.h:328:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
#  export CFLAGS="-march=native -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -Wno-trigraphs"
  export CFLAGS="$CFLAGS -O2 -fbuiltin -g -Wno-error" # -U_FORTIFY_SOURCE"
  msg2 "$CFLAGS" #XXX: don't use `echo` (msg2 is ok), because echo makes updpkgsums put output in PKGBUILD right above sha512sums line!!
#  export CXXFLAGS="$CXXFLAGS"
  export CXXFLAGS="$CXXFLAGS -O2 -fbuiltin -g -Wno-error" # -U_FORTIFY_SOURCE"
  msg2 "$CXXFLAGS"
  export CPPFLAGS="$CPPFLAGS -O2 -fbuiltin -g -Wno-error" # -U_FORTIFY_SOURCE"
  msg2 "$CPPFLAGS"
  #use quotes for msg2 or else you only see -O2 instead of everything else too!

  morestuff="--enable-debug"
#  morestuff="--disable-debug"
  #XXX: not using --enable-debug because: Nevermind, workaround: -Wno-error  to not treat warnings as errors
  #sensors-plugin.c: In function ‘_xpp_realize’:
  #sensors-plugin.c:2361:9926: error: passing argument 1 of ‘gtk_widget_get_realized’ from incompatible pointer type [-Werror]
  # XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (sensors_plugin_construct);
  #FIXed: --disable-debug hits the same warning, except it's not treated as error, so find a way to disable treating warnings as errors! -Wno-error

  msg "yes DEBUG"
else
  msg "no DEBUG"
  morestuff="--disable-debug"
fi


pkgver() {
  cd "$_gitname"
  git describe --tags --always | sed 's/-/./g'
}

prepare() {
  cd "$_gitname"

  # Satisfy the check that hddtemp is queryable via netcat
  # (https://bugs.archlinux.org/task/28275)
  echo ohai | nc -l -p 7634 -s localhost -c &

  sed -e 's/configure.in.in/configure.ac.in/g' -i autogen.sh

#  patch -Np1 -i "../$patch1"
#  patch -Np1 -i "../$patch2"

  echo "#generated by PKGBUILD" >aclocal.m4
  for i in codeset.m4 gettext.m4 glibc21.m4 iconv.m4 isc-posix.m4 lcmessage.m4 progtest.m4; do
    f="/usr/share/aclocal/$i"
    if [ -e "$f" ]; then
      cat "$f" >>aclocal.m4
    else
      msg "avoiding inexistent file $f"
    fi
  done

  mkdir -pv -- m4

  ./autogen.sh --prefix=/usr \
	--sysconfdir=/etc \
	--libexecdir=/usr/lib \
	--localstatedir=/var \
  --datadir=/usr/share \
  --datarootdir=/usr/share \
	--disable-static \
	--with-pathhddtemp=/usr/sbin/hddtemp \
  $morestuff


}

build() {
  cd "${_gitname}"
  
	
  make -j1
}

package() {
  cd "${_gitname}"
  make DESTDIR="${pkgdir}" install
}
# vim:set ts=2 sw=2 et:
